<?php

namespace app\controller\admin\wzg;

use app\model\admin\wzg\WzGetRune;
use http\Client;
use laytp\controller\Backend;
use laytp\library\CommonFun;

/**
 * Class Equipment
 * @package app\controller\admin\wzg
 */
class Rune extends Backend
{
    /**
     * api_log模型对象
     * @var \app\model\api\Log
     */
    protected $model;
    protected $hasSoftDel=0;//是否拥有软删除功能

    protected $noNeedLogin = []; // 无需登录即可请求的方法
    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法

    public $orderRule = ['id' => 'asc'];

    protected $attrName = [
      'max_hp' => '最大生命',
      'movement' => '移速',
      'cool_time' => '冷却缩减',
      'atk_speed' => '攻击速度',
      'hp_rec' => '五秒回血',
      'phy_atk' => '物理攻击',
      'spe_atk' => '法术攻击',
      'phy_through' => '物理穿透',
      'spe_through' => '法术穿透',
      'phy_blood' => '物理吸血',
      'spe_blood' => '法术吸血',
      'crit_rat' => '暴击率',
      'crit_eff' => '暴击效果',
      'phy_def' => '物理防御',
      'spe_def' => '法术防御',
    ];

    public function _initialize()
    {
        $this->model = new WzGetRune();
    }

    /**
     * 列表
     *  all_data参数的值为true时，表示查询表中所有数据集，否则进行分页查询
     * @return mixed
     */
    public function index()
    {
        $where   = $this->buildSearchParams();
        $order   = $this->buildOrder();
        $allData = $this->request->param('all_data');
        if ($allData) {
            $data = $this->model->where($where)->order($order)->cache(true)->select()->toArray();
        } else {
            $limit = $this->request->param('limit', 10);
            $data  = $this->model->where($where)->order($order)->paginate($limit)->toArray();
            foreach ($data['data'] as &$item){
                $item['attr'] = [];
                foreach ($item as $ke=>$it){
                    if(isset($this->attrName[$ke])&&!empty($it)){
                        $item['attr'][] = $this->attrName[$ke]." +".$it;
                    }
                }
                $item['attr'] = implode("；",$item['attr']);
            }
        }
        return $this->success('数据获取成功', $data);
    }
}